package org.example;


import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class ExcelReader {
    public static void main(String[] args) {
        try (FileInputStream fis = new FileInputStream(new File("C:/Users/47868/Desktop/劳动教育.xlsx"));
             Workbook workbook = new XSSFWorkbook(fis)) {

            // 获取第一个工作表
            Sheet sheet = workbook.getSheetAt(0);

            // 遍历每一行
            for (Row row : sheet) {
                StringBuilder rowData = new StringBuilder();
                // 遍历每一列
                for (Cell cell : row) {
                    // 根据单元格类型获取值
                    switch (cell.getCellType()) {
                        case STRING:
                            rowData.append(cell.getStringCellValue()).append("\t");
                            break;
                        case NUMERIC:
                            if (DateUtil.isCellDateFormatted(cell)) {
                                rowData.append(cell.getDateCellValue()).append("\t");
                            } else {
                                rowData.append(cell.getNumericCellValue()).append("\t");
                            }
                            break;
                        case BOOLEAN:
                            rowData.append(cell.getBooleanCellValue()).append("\t");
                            break;
                        case FORMULA:
                            rowData.append(cell.getCellFormula()).append("\t");
                            break;
                        default:
                            rowData.append("").append("\t");
                    }
                }
                String line = rowData.toString();
                //System.out.println(line);
                if (line.contains("张庭豪")) {
                    System.out.println(line);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
